package com.zeny.coding.advice;


import com.zeny.coding.dto.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName GlobalExceptionAdvice
 * @Description 统一异常处理
 * @Author zeny
 */
@SuppressWarnings("all")
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    /**
     * <h2>处理通用异常</h2>
     * @param request
     * @param e
     **/
    @ExceptionHandler(value = Exception.class)
    public Response handlerCommonException(HttpServletRequest request, Exception e) {
        log.error("发生异常: {}", e.getMessage());
        return new Response().exception().message(e.getMessage());
    }
}
